﻿using ProjectFootball.MVC.Foundation;
using ProjectFootball.MVC.Foundation.ResourceLibrary;
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Security.Principal;

namespace ProjectFootball.MVC.Models.EntityFramework.Entities
{
    public class Person : BaseApprovableEntity, IApprovableEntity
    {
        #region Constructors
        public Person()
        {
        }

        public Person(IPrincipal user, CreateType createType, Guid approvalGuid, string forenames, string surname, DateTime? dob, Guid? countryGuid, DateTime activeFrom, DateTime activeTo)
            :base(user, createType, approvalGuid)
        {
            Forenames = forenames;
            Surname = surname;
            Dob = dob;
            CountryGuid = countryGuid;
            ActiveFrom = activeFrom;
            ActiveTo = activeTo;
        }
        #endregion

        [StringLength(50)]
        public string Forenames { get; set; }

        [StringLength(30)]
        [Required]
        public string Surname { get; set; }

        public DateTime? Dob { get; set; }

        [ForeignKey("Country")]
        public Guid? CountryGuid { get; set; }

        public DateTime ActiveFrom { get; set; }

        public DateTime ActiveTo { get; set; }

        [ForeignKey("CountryGuid")]
        public virtual Country Country { get; set; }

        [NotMapped]
        public string FullName
        {
            get { return string.IsNullOrEmpty(Forenames) ? Surname : string.Format("{0} {1}", Forenames, Surname); }
        }
    }
}